<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<script type="text/javascript">
	var shopGoodsDataGrid;
    $(function() {
        shopGoodsDataGrid = $('#shopGoodsDataGrid').datagrid({
        url : '${path}/shopGoods/dataGrid',
        striped : true,
		rownumbers : true,
		pagination : true,
		singleSelect : true,
		fitColumns:false,
				idField : 'goodId',
		sortName : 'goodId',
																																																																		sortOrder : 'asc',
		pageSize : 20,
		pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,400, 500 ],
		frozenColumns : [ [	
						   {
            title : '商品编号',
            field : 'goodId',
            sortable : true
        }, 
								   {
            title : '商品名称',
            field : 'goodName',
            sortable : true
        }, 
								   {
            title : '商品号',
            field : 'goodCode',
            sortable : true
        }, 
								   {
            title : '商品主标题',
            field : 'goodParentTitle',
            sortable : true
        }, 
								   {
            title : '商品副标题',
            field : 'goodSubTitle',
            sortable : true
        }, 
								   {
            title : '商品价格(分)',
            field : 'goodPrice',
            sortable : true
        }, 
								   {
            title : '商品描述',
            field : 'goodDescription',
            sortable : true
        }, 
								   {
            title : '库存数量',
            field : 'goodNum',
            sortable : true
        }, 
								   {
            title : '创建时间',
            field : 'createTime',
            sortable : true
        }, 
								   {
            title : '创建人编号',
            field : 'createUserId',
            sortable : true
        }, 
								   {
            title : '商品条形码',
            field : 'goodBarcode',
            sortable : true
        }, 
								   {
            title : '商品状态(1-正常，2-下架，3-删除)',
            field : 'goodStatus',
            sortable : true
        }, 
								   {
            title : '商品卖点',
            field : 'sellPoint',
            sortable : true
        }, 
								   {
            title : '更新时间',
            field : 'updateTime',
            sortable : true
        }, 
								   {
            title : '商品排序值',
            field : 'goodOrder',
            sortable : true
        }, 
								   {
            title : '折扣率(1-100)',
            field : 'depositRate',
            sortable : true
        }, 
				        {
            field : 'action',
            title : '操作',
            width : 200,
            formatter : function(value, row, index) {
                var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoods-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="shopGoodsEditFun(\'{0}\');" >编辑</a>', row.goodId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoods-easyui-linkbutton-verify" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="shopGoodsVerifyFun(\'{0}\');" >审核</a>', row.goodId);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoods-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="shopGoodsDeleteFun(\'{0}\');" >删除</a>', row.goodId);
								                				                				                				                				                				                				                				                				                				                				                				                				                				                				                				                return str;
            }
        } ] ],
        onLoadSuccess:function(data){
            $('.shopGoods-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.shopGoods-easyui-linkbutton-verify').linkbutton({text:'审核'});
            $('.shopGoods-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#shopGoodsToolbar'
    });
});

/**
 * 添加框
 * @param url
 */
function shopGoodsAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : 700,
        height : 600,
        href : '${path}/shopGoods/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = shopGoodsDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#shopGoodsAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 编辑
 */
function shopGoodsEditFun(id) {
    if (id == undefined) {
        var rows = shopGoodsDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        shopGoodsDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : 700,
        height : 600,
        href :  '${path}/shopGoods/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = shopGoodsDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#shopGoodsEditForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 删除
 */
 function shopGoodsDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = shopGoodsDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         shopGoodsDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/shopGoods/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     shopGoodsDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}


/**
 * 清除
 */
function shopGoodsCleanFun() {
    $('#shopGoodsSearchForm input').val('');
    shopGoodsDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function shopGoodsSearchFun() {
     shopGoodsDataGrid.datagrid('load', $.serializeObject($('#shopGoodsSearchForm')));
}
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',border:false"
		style="height: 30px; overflow: hidden;background-color: #fff">
		<form id="shopGoodsSearchForm">
			<table>
				<tr>
					<th>名称:</th>
					<td><input name="name" placeholder="搜索条件" />
					</td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-magnifying-glass',plain:true"
						onclick="shopGoodsSearchFun();">查询</a> <a
						href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-x-circle',plain:true"
						onclick="shopGoodsCleanFun();">清空</a></td>
				</tr>
			</table>
		</form>
	</div>

	<div data-options="region:'center',border:false">
		<table id="shopGoodsDataGrid" data-options="fit:true,border:false"></table>
	</div>
</div>
<div id="shopGoodsToolbar" style="display: none;">
	<a onclick="shopGoodsAddFun();" href="javascript:void(0);"
		class="easyui-linkbutton"
		data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>